package norm.reference

class UserController {

	def scaffold = true 
	def normReferenceUtilityService
	
    def login = {
	}
	
	def doLogin = {
		def user = User.findByUsernameAndPassword(params.username, params.password)
		if(user)
		{
			session.user = user
			flash.message = "Hello ${user.username}!"
			normReferenceUtilityService.serviceMethod()
			redirect(controller:"user", action:"list")
		}
		else
		{
			flash.message = "Sorry, ${params.username}. Please try again."
			redirect(action:"login")
		}
	}
	
	def logout = {
		flash.message = "Goodbye ${session.user.username}"
		session.user = null
		redirect(controller:"user", action:"list")
	}
	
	def auth() {
		if(!session.user)
		{
			redirect(controller:"user", action:"login")
			return false
		}
		
	}
	
	//def beforeInterceptor = [action:this.&auth, except:["index", "list", "show"]]
}
